package service;

import common.Message;
import common.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

//存放离线消息
public class MangeMessage {
    public static ConcurrentHashMap<String, ArrayList<Message>> noSendMessage = new ConcurrentHashMap<>();

    public static void  addMessage(String userId,Message message)
    {
        //判断是否已经存在未发消息，有就追加，没有就新建
        if(noSendMessage.containsKey(userId))
        {
            ArrayList<Message> messages = noSendMessage.get(userId);
            messages.add(message);
        }else
        {
            ArrayList<Message> messages = new ArrayList<>();
            messages.add(message);
            noSendMessage.put(userId,messages);
        }
    }

    public static ArrayList<Message> getMessage(String userId)
    {
       return noSendMessage.get(userId);
    }

    public static boolean hasMessage(String userId)
    {
       return noSendMessage.containsKey(userId);
    }

    public static void removeMessage(String userId)
    {
        noSendMessage.remove(userId);
    }
}
